use redis::{AsyncCommands, Client};
const DSN: &str = "redis://127.0.0.1:6379";

pub async fn gen_pool(redis_dsn: String) -> Result<redis::aio::MultiplexedConnection, String> {
    let client = Client::open(redis_dsn).map_err(|e| e.to_string())?;
    let conn = client
        .get_multiplexed_async_connection()
        .await
        .map_err(|err| err.to_string())?;

    Ok(conn)
}

#[tokio::main]
async fn main() {
    let mut pool = gen_pool(DSN.to_owned()).await.unwrap();

    let key = "status";
    let value = 0;
    let _: () = pool.set(key, value).await.unwrap();
    println!("Successfully set value for '{}'", key);

    let retrieved_value: i32 = pool.get(key).await.unwrap();
    println!("Successfully retrieved value: {}", retrieved_value);
}
